package com.banciyuan.bcywebview.biz.circles.smooth.viewholder;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.base.helper.push.Item.BasePush;
import com.banciyuan.bcywebview.base.helper.push.PushFactory;
import com.banciyuan.bcywebview.base.util.BaseObserver;
import com.banciyuan.bcywebview.utils.common.UIUtils;

import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by squall on 2017/4/14.
 */

public class HotHeaderHolder extends RecyclerView.ViewHolder {

    private TextView banner_text;
    private View rela_line;
    private View banner_line;
    private View split_line;
    private LinearLayout rela_container;
    private View category_check;
    private View sec_split_line;
    private View boardcast_line;

    public HotHeaderHolder(View itemView) {
        super(itemView);
        banner_text = (TextView) itemView.findViewById(R.id.banner_text);
        rela_line = itemView.findViewById(R.id.relate_circleview);
        banner_line = itemView.findViewById(R.id.banner);
        rela_container = (LinearLayout) itemView.findViewById(R.id.circles_viewcontanier);
        split_line = itemView.findViewById(R.id.relate_space);
        category_check = itemView.findViewById(R.id.category_check);
        sec_split_line = itemView.findViewById(R.id.sec_split_line);
        boardcast_line = itemView.findViewById(R.id.boardcast_line);
    }

    public void renderHeader(final Context mContext, final Timeline mItem) {
        int count = 0;
        category_check.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseObserver.getInstance().notifyWatchers(BaseObserver.CIRCLE_GONEWEST);
            }
        });
        if (mItem.getAffiche() != null && !TextUtils.isEmpty(mItem.getAffiche().getText())) {
            banner_line.setVisibility(View.VISIBLE);
            banner_text.setText(Html.fromHtml(mItem.getAffiche().getText()));
            if (!TextUtils.isEmpty(mItem.getAffiche().getLink())) {
                banner_text.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        BasePush basePush = PushFactory.getPush(mItem.getAffiche().getLink());
                        basePush.goPushActivity(mContext, true);
                    }
                });
            }
        } else {
            banner_line.setVisibility(View.GONE);
            count++;
        }
        rela_line.setVisibility(View.GONE);
        count++;
        if (count == 2) {
            LinearLayout.LayoutParams ll6 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIUtils.dip2px(6, mContext));
            sec_split_line.setLayoutParams(ll6);
            split_line.setVisibility(View.GONE);
        } else {
            LinearLayout.LayoutParams ll8 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIUtils.dip2px(8, mContext));
            sec_split_line.setLayoutParams(ll8);
            LinearLayout.LayoutParams ll6 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, UIUtils.dip2px(6, mContext));
            split_line.setLayoutParams(ll6);
        }

    }
}
